//
//  SystemMessageList.m
//  安好
//
//  Created by lianchuang on 14/11/7.
//  Copyright (c) 2014年 冯凯. All rights reserved.
//
//************************************这个类没有用，不用耽误时间看**************************

#import "SystemMessageList.h"

@implementation SystemMessageList
/**
 *  获取所有的安好系统消息
 *
 *  @return 返回所有安好发送的消息
 */
+(NSMutableArray *)readAllSystemMessageLists
{
    FMDatabase *db=[MyFMDB openDB];
    NSUserDefaults *userDefaults= [NSUserDefaults standardUserDefaults];
    NSString * myuid = [userDefaults objectForKey:@"SelfUidKey"];
    NSString * sql = [NSString stringWithFormat:@"select * from AnHaoSystem where myuid = %@ order by dateline desc", myuid];
    FMResultSet *rs=[db executeQuery:sql];
    NSMutableArray *array=[[NSMutableArray alloc]init];
    while ([rs next]) {
        SystemMessageList * systemList = [[SystemMessageList alloc] init];
        systemList.date = [rs stringForColumn:@"date"];
        systemList.imageURL=[rs stringForColumn:@"imageURL"];
        systemList.content=[rs stringForColumn:@"content"];
        systemList.title=[rs stringForColumn:@"title"];
        systemList.fid=[rs stringForColumn:@"fid"];
        systemList.noread=[rs stringForColumn:@"noread"];
        [array addObject:systemList];
    }
    [db close];
    return array;
}
/**
 *  根据每条消息的fid，删除对应的安好系统消息
 *
 *  @param fid 安好消息的唯一标识
 *
 *  @return 是否删除成功
 */
+ (BOOL)deleteAnHaoSystemListWithFid:(NSString *)fid
{
    FMDatabase *db=[MyFMDB openDB];
    NSUserDefaults *userDefaults= [NSUserDefaults standardUserDefaults];
    NSString * myuid = [userDefaults objectForKey:@"SelfUidKey"];
    BOOL success=[db executeUpdate:@"delete from AnHaoSystem where fid=? and myuid=?",fid,myuid];
    [db close];
    return success;

}
+ (NSMutableArray *)readSystemListLastMessage
{
    NSUserDefaults *userDefaults= [NSUserDefaults standardUserDefaults];
    NSString * myuid = [userDefaults objectForKey:@"SelfUidKey"];
    NSString *sql = [NSString stringWithFormat:@"select * from AnHaoSystem order by date  where myuid=%@ limit 1", myuid];
    FMDatabase *db=[MyFMDB openDB];
    FMResultSet *rs=[db executeQuery:sql];
    NSMutableArray *array=[[NSMutableArray alloc]init];
    while ([rs next]) {
        SystemMessageList *system=[[SystemMessageList alloc]init];
        system.myuid=[rs stringForColumn:@"myuid"];
        system.fid=[rs stringForColumn:@"fid"];
        system.title=[rs stringForColumn:@"title"];
        system.imageURL=[rs stringForColumn:@"imageURL"];
        system.content=[rs stringForColumn:@"content"];
        system.date=[rs stringForColumn:@"date"];
        system.noread=[rs stringForColumn:@"noread"];
        [array addObject:system];
    }
    [db class];
    return array;
}
//************************************这个类没有用，不用耽误时间看**************************

@end
